package cn.stylefeng.guns.modular.system.service.ActivityEvent;

import cn.stylefeng.guns.modular.system.entity.DispatchOrder;
import cn.stylefeng.guns.modular.system.entity.IndentOrder;
import cn.stylefeng.guns.modular.system.entity.SendGoods;
import cn.stylefeng.guns.modular.system.service.DispatchOrderService;
import cn.stylefeng.guns.modular.system.service.IndentOrderService;
import cn.stylefeng.guns.modular.system.service.SendGoodsService;
import cn.stylefeng.guns.sys.core.util.utility.StatusCode;
import cn.stylefeng.roses.core.util.SpringContextHolder;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.activiti.engine.delegate.DelegateExecution;
import org.activiti.engine.delegate.ExecutionListener;

/**
 * @Author : xiaofei
 * @Date: 2019/7/27
 */
public class sendOrderEnvent implements ExecutionListener {

    private DispatchOrderService dispatchOrderService = SpringContextHolder.getBean(DispatchOrderService.class);

    @Override
    public void notify(DelegateExecution delegateExecution) {

        String eventName = delegateExecution.getEventName();
        DispatchOrder dispatchOrder = dispatchOrderService.getOne(new QueryWrapper<DispatchOrder>()
                .lambda().eq(DispatchOrder::getProcessInstanceId,delegateExecution.getProcessInstanceId()));
        if ("end".equals(eventName)){
            dispatchOrder.setCheckCode(StatusCode.FAIL.getVal());
        }else if ("start".equals(eventName)){
            dispatchOrder.setCheckCode(StatusCode.SUCCESS.getVal());
        }
        dispatchOrderService.getBaseMapper().updateById(dispatchOrder);
    }



}
